package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.common.constant.ClueStatusConstants;
import com.qk.domain.clue.ClueDO;
import com.qk.domain.clue.CluePoolDO;
import com.qk.dto.clue.*;
import com.qk.entity.Clue;
import com.qk.management.aop.anno.LoginAnno;
import com.qk.management.service.ClueService;
import com.qk.vo.clue.ClueVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;


/**
 * &#064;author：zzq
 * &#064;createTime：2025/10/13 18:26
 * &#064;description： 线索管理控制器
 */
@RestController
@RequestMapping("/clues")
@SuppressWarnings("all")
public class ClueController {
    @Autowired
    private ClueService clueService;

    //伪线索处理
    @PutMapping("/false/{id}")
    @LoginAnno
    public Result toFalseClue(@PathVariable Integer id,@RequestBody MarkFalseClueDto dto){
        clueService.toFalseClue(id,dto);
        return Result.success();
    }

    //线索转商机
    @PutMapping("/toBusiness/{id}")
    @LoginAnno
    public Result toBusiness(@PathVariable Integer id) {
        clueService.toBusiness(id);
        return Result.success();
    }

    //跟进线索
    @LoginAnno
    @PutMapping
    public Result updateClueInfoById(@RequestBody UpdateClueInfoDTO dto) {
        clueService.updateClueInfoById(dto);
        return Result.success();
    }

    //线索列表展示
    @GetMapping
    public Result list(ClueListDTO dto) {
        PageResult<ClueDO> result = clueService.clueList(dto);
        return Result.success(result);
    }

    //线索池列表展示
    @GetMapping("/pool")
    public Result cluePoolList(CluePoolListDTO dto) {
        PageResult<CluePoolDO> cluePoolList = clueService.cluePoolList(dto);
        return Result.success(cluePoolList);
    }

    @LoginAnno
    @PostMapping
    public Result addClue(@RequestBody ClueDTO dto) {
        clueService.addClue(dto);
        return Result.success();
    }

    @LoginAnno
    @PutMapping("/assign/{clueId}/{userId}")
    public Result updateClueById(@PathVariable Integer clueId, @PathVariable Integer userId) {
        clueService.updateById(Clue.builder()
                .id(clueId)
                .userId(userId)
                .updateTime(LocalDateTime.now())
                .status(ClueStatusConstants.WAIT_FOLLOW_UP)
                .build());
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getClueInfoById(@PathVariable Integer id) {
        ClueVO vo = clueService.getClueInfoById(id);
        return Result.success(vo);
    }

}
